#ifndef DOUBAN_DOUMAIL_MAILCREATOR_H
#define DOUBAN_DOUMAIL_MAILCREATOR_H

#include "data/DoubanUser.h"
#include <QPlainTextEdit>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>

class QDialog;
class QNetworkReply;

namespace Douban
{
	class DoubanUser;
	class DoubanContext;
	class MailCreator : public QFrame
	{
		Q_OBJECT
		public:
			void sendMail(const DoubanUser& toWhom);
			void setAutoClose(bool b){b_autoClose = b;}

			MailCreator(DoubanContext*);
			~MailCreator();

			void freeResource();
		protected:
			void closeEvent(QCloseEvent*);
		private:
			DoubanContext*	m_context;
			bool			b_autoClose;
			bool			b_waitingForUserIcon;
			DoubanUser		m_currentReceiver;

			QLabel			iconLabel;
			QLabel			nameLabel;
			QLabel			hintLabel;
			QPushButton		sendBtn;
			QLineEdit		titleText;
			QPlainTextEdit	outText;

			QNetworkReply*	m_sendMailReply;
			QNetworkReply*	m_getCatchaReply;

			QDialog*		verifyDialog;
			QLabel*			verifyLabel;
			QLineEdit*		verifyText;
			QPushButton*	verifyBtn;
			QString			captcha_token;
		private slots:
			void updateSendBtn();
			void onSendBtnClicked();
			void iconAvailable();
			void onPostFinished();

			void onGetCatcha();
			void updateVerifyBtn();
			void sendMailWithVerifyCode();
		private:
			static const QString Doumail_Post_Entry_Plus;
			static const QString Doumail_Piece_URL;
			static const QString Doumail_Post_URL;
			static const QString Doumail_Post_Entry;
	};
}
#endif // MAILCREATOR_H
